// 测试日志

#include <iostream>
#include <pthread.h>
#include <vector>
#include "Log.hpp"
#include "Mutex.hpp"
using namespace LogModel;
int data = 1;
Mutex mutex;
void *routinue(void *args)
{
    std::string name = static_cast<const char *>(args);
    {
        LockGuard lockguard(mutex);
        int cnt = 5;
        while (cnt--)
        {
            data++;
            LOG(LogLevel::DEBUG) << "我是新线程 : " << name << " , data = " << data;
        }
    }
    return nullptr;
}

int main()
{
    std::vector<pthread_t> threads;

    // 选择刷新策略 -- 选择显示器
    Enable_Console_Log_Strategy();
    // 创建多线程看一看效果
    for (int i = 1; i < 5; ++i)
    {
        pthread_t tid;
        char *name = new char[64];
        snprintf(name, 64, "thread-%d", i);
        int n = pthread_create(&tid, nullptr, routinue, name);
        if (n == 0)
        {
            LOG(LogLevel::DEBUG) << "creat " << name << " success !";
            threads.emplace_back(tid);
        }
        else
        {
            LOG(LogLevel::ERROR) << "creat " << name << " fail !";
        }
    }

    for (auto &thread : threads)
    {
        int n = pthread_join(thread, nullptr);
        if (n == 0)
        {
            LOG(LogLevel::DEBUG) << "Join thread success !";
        }
    }

    return 0;
}